home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / DTS MPW Goodies / CheckWindowOut < prev    next >
Encoding:
Text File  |  1990-09-14  |  4.5 KB  |  178 lines  |  [TEXT/MPS ]

  1. #    File:        CheckWindowOut
  2. #
  3. #    Contains:    script to check a window out for modification
  4. #
  5. #    Usage:        CheckWindowOut window
  6. #
  7. #    Status:        CheckWindowOut may return the following status values:
  8. #
  9. #                    0        the window was checked out
  10. #                    1        error
  11. #                    2        the user canceled
  12. #
  13. #                CheckWindowOut uses the ProjectInfo command to determine the
  14. #                parent project for a file open as a window. Once this project
  15. #                has been determined, the file can be properly checked out.
  16. #                A dialog allows the user to type in a short comment that
  17. #                indicates what the reason for checking the file out was.
  18. #                This will be logged into the project, and into the file.
  19. #
  20. #    Written by:    Darin Adler and scott douglass
  21. #
  22. #    Copyright:    © 1988, 1989 by Apple Computer, Inc., all rights reserved.
  23. #
  24. #    Change History: (maintain by hand, CheckWindowOut confuses itself by editing itself)
  25. #
  26. #                11/21/89    dba        made it work with the new headers
  27. #                11/8/89        dba        stopped using LastChange marker; invented mark character
  28. #
  29. #    To Do:
  30. #        a way to start a new branch
  31. #        a way to specify a “task”
  32. #
  33.  
  34. Set Exit 0
  35.  
  36. # the following helps to debug until MPW sends echos to Dev:Console instead of Dev:StdErr
  37.  
  38. If {Echo}
  39.     Set somewhere "∑∑ '{Worksheet}'"
  40. Else
  41.     Set somewhere "∑ Dev:Null"
  42. End
  43.  
  44. Begin
  45.  
  46.     Set Comment "{SystemFolder}Comment"    # file to compose comment in
  47.     Set Window "{1}"
  48.  
  49.     # get short name of window
  50.  
  51.     If "{Window}" !~ /:*([¬:]+:*)*([¬:]+)®1/
  52.         Alert "Can’t parse window parameter."
  53.         Exit 1
  54.     End
  55.     Set Short "{®1}"                    # get short name for dialogs
  56.     Set Cant "“{Short}” can’t be checked out "
  57.  
  58.     # check what project the window belongs to
  59.  
  60.     Set Info "`ProjectInfo "{Window}"`"
  61.     If "{Info}" !~ /≈Project: ([¬:]+∫)®1     Checked out:≈/
  62.         Alert "{Cant}because it doesn’t belong to a project."
  63.         Exit 1
  64.     End
  65.     Set Project "{®1}"
  66.  
  67.     # check if the window is already checked out
  68.  
  69.     If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂+≈/
  70.         Alert "{Cant}again because it’s already checked out for modification."
  71.         Exit 1
  72.     End
  73.  
  74.     # check if the window is ModifyReadOnly'd
  75.  
  76.     If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂*≈/
  77.         Alert "{Cant}because it’s a modified read-only copy."
  78.         Exit 1
  79.     End
  80.  
  81.     # get the version that is checked out
  82.  
  83.     If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
  84.         Alert "Can’t parse ProjectInfo."
  85.         Exit 1
  86.     End
  87.     Set OldVersion {®1}
  88.  
  89.     # check if the project is mounted
  90.  
  91.     ProjectInfo -project "{Project}" -only ∑ Dev:Null
  92.     If {Status}
  93.         Alert "{Cant}because the project “{Project}” is not mounted."
  94.         Exit 1
  95.     End
  96.  
  97.     # see if the file is already checked out
  98.  
  99.     Set Info "`ProjectInfo -latest -comments -project "{Project}" "{Short}"`"
  100.     If "{Info}" == ""
  101.         Alert "{Cant}because it isn’t really in the project “{Project}”."
  102.         Exit 1
  103.     Else If "{Info}" =~ /≈Owner: ([¬:]+)®1     Checked out:≈Comment: +(≈)®2/
  104.         Set Owner "{®1}"
  105.         Set Comment "{®2}"
  106.         If "{Owner}" == "{User}"
  107.             Alert "{Cant}because you have already checked it out elsewhere.  Comment: “{Comment}”"
  108.             Exit 1
  109.         Else
  110.             Alert "{Cant}because it has already been checked out by {Owner}.  Comment: “{Comment}”"
  111.             Exit 1
  112.         End
  113.     End
  114.  
  115.     # get position within window so we can return to it later
  116.  
  117.     If `Position -c "{Window}"` !~ /([0-9]+)®1,([0-9]+)®2/
  118.         Alert "Can’t parse Position output."
  119.         Exit 1
  120.     End
  121.     Set SelectionStart {®1}
  122.     Set SelectionSize `Evaluate {®2}-{®1}`
  123.  
  124.     # get a comment about the change
  125.  
  126.     Set IgnoreCmdPeriod 1
  127.     Echo -n "{DefaultComment}" | CoolRequest -d -q "What are you are going to change in “{Short}”?" >"{Comment}"
  128.     Set CommentStatus {Status}
  129.     Set IgnoreCmdPeriod 0
  130.     If {CommentStatus}
  131.         Delete -i "{Comment}"
  132.         Exit 2
  133.     End
  134.  
  135.     # check the file out
  136.  
  137.     CheckOut -cf "{Comment}" -m -project "{Project}" "{Window}" || Set CheckOutStatus {Status}
  138.     If {CheckOutStatus}
  139.         Delete -i "{Comment}"
  140.         # *** need to check this more closely (Cancel from dialog gets here)
  141.         Alert "CheckOut failed!"
  142.         Exit 1
  143.     End
  144.  
  145.     Find •!{SelectionStart}:§!{SelectionSize} "{Window}"
  146.  
  147.     # get the version number
  148.  
  149.     Set Info "`ProjectInfo -s "{Window}"`"
  150.     If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
  151.         Alert "Can’t parse ProjectInfo."
  152.         Exit 1
  153.     End
  154.     Set Version "{®1}"
  155.  
  156.     # add the comment to the change history
  157.  
  158.     If {ProjectHeaders}
  159.         Mark -y § OldSelection "{Window}"
  160.             AddChange "{Window}" "{Version}+" "{Comment}"
  161.         Find OldSelection "{Window}"
  162.         Unmark OldSelection "{Window}"
  163.         Save "{Window}"
  164.     End
  165.  
  166.     Delete -i "{Comment}"
  167.  
  168.     Set Increment `Evaluate {Version} - {OldVersion}`
  169.     If {Increment} > 0
  170.         If {Increment} == 1
  171.             Alert "The “{Short}” that you just checked out is a version newer than your old copy."
  172.         Else
  173.             Alert "The “{Short}” that you just checked out is {Increment} versions newer than your old copy."
  174.         End
  175.     End
  176.  
  177. End {somewhere}
  178.